﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Diagnostics;
using mesoBoard.Data;
using mesoBoard.Data.Repositories;
using mesoBoard.Services;
using mesoBoard.Common;

namespace mesoBoard.Web.Providers
{
   public static class mbStuff
   {
       public static bool HasSpecialPermission(SpecialPermissions permission)
       {
           Roles roleService = new Roles(new RepositoriesWrapper(new mbEntities()));
           bool hasPermission = roleService.UserHasSpecialPermissions(int.Parse(HttpContext.Current.User.Identity.Name), permission);

           if (permission == SpecialPermissions.Moderator && !hasPermission)
               return roleService.UserHasSpecialPermissions(int.Parse(HttpContext.Current.User.Identity.Name), SpecialPermissions.Administrator);
           else
               return hasPermission;
       }

       public static User CurrentUser
       {
           get
           {
               if (!HttpContext.Current.User.Identity.IsAuthenticated)
                   return null;
               UserRepository usrs = new UserRepository(new mbEntities());
               return usrs.GetUser(int.Parse(HttpContext.Current.User.Identity.Name));
               
           }
       }
   }
}